<template>
    <el-dialog title="请购明细" :visible.sync="open" width="80%" v-dialogDrag :append-to-body="true" @close="handleClose">
        <el-col :span="24">
            <el-row :gutter="10">
                <el-col :span="24">
                    <el-card class="box-card">
                        <el-descriptions class="margin-top " :contentStyle="CS" :label-style="LS" title="" :column="3"
                            size="medium" border>
                            <el-descriptions-item>
                                <template slot="label">
                                    <i class="el-icon-c-scale-to-original"></i>
                                    请购单号
                                </template>
                                {{ form.nos }}
                            </el-descriptions-item>
                            <el-descriptions-item>
                                <template slot="label">
                                    <i class="el-icon-c-scale-to-original"></i>
                                    质检人
                                </template>
                                {{ form.createBy }}
                            </el-descriptions-item>
                            <el-descriptions-item>
                                <template slot="label">
                                    <i class="el-icon-bank-card"></i>
                                    供应商名称
                                </template>
                                {{ form.supplierName }}
                            </el-descriptions-item>
                            <el-descriptions-item>
                                <template slot="label">
                                    <i class="el-icon-user"></i>
                                    采购日期
                                </template>
                                {{ parseTime(form.ddDate, '{y}-{m}-{d}') }}
                            </el-descriptions-item>
                            <el-descriptions-item>
                                <template slot="label">
                                    <i class="el-icon-user"></i>
                                    订单金额
                                </template>
                                {{ form.money }}
                            </el-descriptions-item>
                            <el-descriptions-item>
                                <template slot="label">
                                    <i class="el-icon-user"></i>
                                    运费
                                </template>
                                {{ form.shippingFee }}
                            </el-descriptions-item>
                            <el-descriptions-item>
                                <template slot="label">
                                    <i class="el-icon-user"></i>
                                    采购类别
                                </template>
                                <dict-tag :options="dict.type.caigou_type" :value="form.ywType" />
                            </el-descriptions-item>
                            <!-- <el-descriptions-item>
                                <template slot="label">
                                    <i class="el-icon-user"></i>
                                    采购类型
                                </template>
                                <dict-tag :options="dict.type.goods_type" :value="form.goodsType" />
                            </el-descriptions-item>
                            <el-descriptions-item>
                                <template slot="label">
                                    <i class="el-icon-user"></i>
                                    申请付款金额
                                </template>
                                {{ form.payApplyTotalMoney }}
                            </el-descriptions-item>
                            <el-descriptions-item>
                                <template slot="label">
                                    <i class="el-icon-user"></i>
                                    实际到货金额
                                </template>
                                {{ form.actualArrivalTotalMoney }}
                            </el-descriptions-item>
                            <el-descriptions-item>
                                <template slot="label">
                                    <i class="el-icon-user"></i>
                                    付款状态
                                </template>
                                <dict-tag style="cursor: pointer;" :options="dict.type.buy_pay_status"
                                    :value="form.payApplyState" />
                            </el-descriptions-item>
                            <el-descriptions-item>
                                <template slot="label">
                                    <i class="el-icon-user"></i>
                                    到货状态
                                </template>
                                <dict-tag style="cursor: pointer;" :options="dict.type.daohuo_status"
                                    :value="form.arrivalStatus" />
                            </el-descriptions-item>
                            <el-descriptions-item>
                                <template slot="label">
                                    <i class="el-icon-user"></i>
                                    定金
                                </template>
                                {{ form.dingjin }}
                            </el-descriptions-item>
                            <el-descriptions-item>
                                <template slot="label">
                                    <i class="el-icon-user"></i>
                                    已付款
                                </template>
                                {{ form.fukuan }}
                            </el-descriptions-item>
                            <el-descriptions-item>
                                <template slot="label">
                                    <i class="el-icon-user"></i>
                                    剩余欠款
                                </template>
                                {{ form.shengyu }}
                            </el-descriptions-item> -->
                        </el-descriptions>
                    </el-card>
                </el-col>
                <el-col :span="24">
                    <el-table :data="goodsSalebuyalllList" ref="table" show-summary :summary-method="getSummaries">
                        <el-table-column sortable label="订单编号" align="center" prop="projectNo" show-overflow-tooltip />
                        <el-table-column sortable label="工程名称" align="center" prop="gongchengName"
                            show-overflow-tooltip />
                        <el-table-column sortable align="center" label="客户名称" prop="customerName" />
                        <el-table-column sortable align="center" label="业务员" prop="salesmanName" />
                        <el-table-column sortable label="交货日期" align="center" prop="deliveryTime" />
                        <el-table-column sortable label="中标价" align="center" prop="goodsTaxUnitPrice" />
                        <el-table-column sortable label="产品编码" align="center" prop="goodsCode" />
                        <el-table-column sortable label="产品名称" align="center" prop="goodsName" show-overflow-tooltip />
                        <el-table-column sortable label="产品型号" align="center" prop="goodModel" show-overflow-tooltip />
                        <el-table-column sortable label="产品状态" align="center" prop="status">
                            <template slot-scope="scope">
                                <dict-tag :options="dict.type.goods_status" :value="scope.row.status" />
                            </template>
                        </el-table-column>
                        <el-table-column sortable label="产品类型" align="center" prop="type" />
                        <el-table-column sortable label="计量单位" align="center" prop="unit" />
                        <el-table-column sortable label="是否自制" align="center" prop="isdo">
                            <template slot-scope="scope">
                                <dict-tag :options="dict.type.isdo" :value="scope.row.isdo" />
                            </template>
                        </el-table-column>
                        <el-table-column sortable align="center" label="请购/自制数量" prop="pleaseBuyCount" />
                        <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip />
                    </el-table>
                </el-col>
            </el-row>
        </el-col>
    </el-dialog>
</template>

<script>
import {
    accAdd,
    deleteAction, downloadFile,
    getAction, getById
} from '@/api/manage'

export default {
    name: "PleaseDetailsFormList",
    dicts: ["apply_pay_status", "apply_assess_status", "goods_status", "daohuo_status", "buy_pay_status", "goods_type", "caigou_type", "isdo"],
    components: {

    },
    props: {
        applyId: {
            type: String,
            default: "",
        },
    },
    watch: {
        applyId: {
            handler(newVal, oldVal) {
                if (newVal) {
                    this.getApplyInfo();
                }
            },
            immediate: true
        },
    },
    data() {
        return {
            open: false,
            activeName: "first",
            // 遮罩层
            loading: true,
            // 总条数
            total: 0,
            goodsSalebuyalllList: [],
            CS: {
                'text-align': 'center',  //文本居中
                'min-width': '250px',   //最小宽度
                'word-break': 'break-all'  //过长时自动换行
            },
            LS: {
                'color': '#000',
                'text-align': 'center',
                'font-weight': '600',
                'height': '40px',
                'min-width': '110px',
                'word-break': 'keep-all'
            },
            form: {},
            url: {
                list: '/goodsSaledo/goodsSaledo/list',
                buyid: '/lvDo/lvDo/'
            },
            queryParams: {
                mainId: null

            },
            queryParams2: {
                id: null

            }

        };
    },
    created() {

    },
    methods: {
        handleClose() {
            this.open = false;
        },
        openDialog(row) {
            this.queryParams.mainId = row.lvdoId;
            this.queryParams2.id = row.lvdoId;
            this.open = true;
            this.getInfo();
        },

        getInfo() {
            getAction(this.url.list, this.queryParams).then(response => {
                this.goodsSalebuyalllList = response.rows
                console.log(this.form, 'datadata')
                this.getList();
                this.loading = false;
            });
        },
        getList() {
            getById(this.url.buyid, this.queryParams2.id).then(response => {
                this.form = response.data;
                this.loading = false;
            });

        },
        getSummaries(param) {
            const { columns, data } = param;
            const sums = [];
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = "合计";
                    return;
                }
                let values;
                if (column.property === "buyDetail.goodsBuyTotal") {
                    values = data.map((item) => Number(item.buyDetail.goodsBuyTotal));
                } else if (column.property === "buyDetail.shengyu") {
                    values = data.map((item) => Number(item.buyDetail.shengyu));
                } else if (column.property === "buyDetail.dun") {
                    values = data.map((item) => Number(item.buyDetail.dun));
                } else {
                    values = data.map((item) => Number(item[column.property]));
                }
                // 只合计amount1和amount3，想合并哪些列就在这里指定
                if (column.property === "orderCount" || column.property === "pleaseBuyCount"
                    || column.property === "goodsBuyPrice" || column.property === "shengyu" || column.property === "goodsBuyTotal") {
                    sums[index] = values.reduce((prev, curr) => {
                        const value = Number(curr);
                        if (!isNaN(value)) {
                            return accAdd(prev, curr);
                        } else {
                            return prev;
                        }
                    }, 0);
                }
            });
            return sums;
        },
    }
};
</script>
